<template>
  <div id="ContactUs">
    <div class="center">
      <img src="@/assets/img/logo.jpeg" class="logo"/>
    </div>

    <van-divider>原测通</van-divider>
    <van-form @submit="onSubmit" v-if="!show">
      <van-field
        v-model="username"
        name="dl_acc"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="dl_mm"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >登录</van-button
        >
        <div class="zc cus" @click="show = true">没有账号? 去注册</div>
      </div>
    </van-form>

    <van-form @submit="onSubmit2" v-if="show">
      <van-field
        v-model="zc.acc"
        name="acc"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写公司名' }]"
      />
      <van-field
        v-model="password2"
        type="password"
        name="mm"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-field
        v-model="zc.mm"
        type="password"
        name="mm2"
        label="确认密码"
        placeholder="密码"
        :rules="[{ required: true, message: '确认密码' }]"
      />

      <van-field
        v-model="zc.lx"
        name="lx"
        label="联系人"
        placeholder="联系人"
        :rules="[{ required: true, message: '联系人' }]"
      />
       <van-field
        v-model="zc.lx2"
        name="lx2"
        label="联系人二"
        placeholder="联系人"
        :rules="[{ required: false, message: '联系人' }]"
      />
      <van-field
        v-model="zc.lx3"
        name="lx3"
        label="联系人三"
        placeholder="联系人"
        :rules="[{ required: false, message: '联系人' }]"
      />
      <van-field
        v-model="zc.phone"
        name="phone"
        label="手机号"
        placeholder="手机号"
        :rules="[{ required: true, message: '手机号' }]"
      />
      <van-field
        v-model="zc.zw"
        name="zw"
        label="职位"
        placeholder="职位"
        :rules="[{ required: true, message: '职位' }]"
      />
      <!-- <van-field
        v-model="zc.kp"
        name="kp"
        label="开票信息"
        placeholder="开票信息"
        :rules="[{ required: true, message: '开票信息' }]"
      /> -->
      <el-upload
        name="upFile"
        class="upload-demo"
       :action='$base+"/api/index/cusupload" '
        
        :on-success="changeWen"
        :on-change="handleChange"
        :before-remove="beforeRemove"
        multiple
        :file-list="fileList"
      >
        <el-button size="small" type="primary">点击上传</el-button>
        <div slot="tip" class="el-upload__tip">上传开票文件</div>
      </el-upload>

      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit2"
          >提交</van-button
        >
        <div class="zc cus" @click="show = false">已有账号? 去登录</div>
      </div>
    </van-form>
  </div>
</template>
<script>
import axios from "axios";
import { WOW } from "wowjs";
// import BMap from "BMap";
import { Field } from "vant";
// import {reg} from '@/api/api'
export default {
  name: "Login",
  data() {
    return {
      fileList: [],
      show: false,
      username: "",
      password: "",
      password2: "",
      zc: {},
    };
  },
  mounted(){
    let lg= localStorage.getItem('lg');
    if(lg){
      this.$router.push('/') 
    };
  },

  methods: {
    onSubmit(values) {
      console.log("submit", values);
      let v = this;
      let data = {
        uname: values.dl_acc,
        upwd: values.dl_mm,
      };
      
      let url=this.$base+'/api/index/getenter'
      axios({
        method: "post",
        data,
        url:url,
        // url: "http://manage.jolinmind.cn/public/api/index/getenter",
        responseType: "text",
      }).then(function (res) {
        console.log("response:", res);
        if (res.data.code == 2) {
          alert(res.data.msg);
        } else {
          localStorage.setItem("lg", "ok");
          localStorage.setItem("user", JSON.stringify(res.data.data));
          v.$router.push("/");
        }
      });

    },
    onSubmit2(values) {
      let that = this;
      console.log("ww:", this.fileList);
      let ff = this.fileList;
      let f_arr = [];

      if (ff.length) {
        for (let i in ff) {
          f_arr.push(ff[i].response.data);
        }
      } else {
        f_arr = "";
      }
      if (values.mm != values.mm2) {
        return alert("输入密码不相同");
      }

      console.log("f_arr:", f_arr, "c:", f_arr);
      let data = {
        company: values.acc,
        pwd: values.mm,
        lian1: values.lx,
        lian2:values.lx2,
        lian3:values.lx3,
        phone1: values.phone,
        job1: values.zw,
        ctext: values.kp,
        tfile: f_arr.length ? f_arr.toString() : "",
      };
      
      this.http.post("index/getcusmsg", data).then((res) => {
        console.log("注册的结果", res);
        if (res.data) {
          alert(res.data.msg);
        }
        if (res.code == 1) {
          alert(res.msg);
        }
      });
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    changeWen(e) {
      console.log("ee:", e, "fileList:", this.fileList);
      //  this.fileList.push(e.data);
      // this.fileList=e.data;
    },
    handleChange(file, fileList) {
      this.fileList = fileList;
      // console.log('666:',fileList)
    },
  },
};
</script>
<style scoped>
.center{
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
}
.logo{
  width: 20vw;
  height: 20vw;
  margin-top: 20px;

}
.zc {
  margin-top: 10px;
  font-size: 20px;
}
.row {
  margin-right: 0;
  margin-left: 0;
}
@media screen and (max-width: 997px) {
  .ContactUs-container {
    padding: 20px 0;
  }
}
</style>

